{extend name="$base" /}
{block name="main"}
<nav class="ns-third-menu js-order-status-menu">
	<ul>
		<li class="selected" onclick="location.href='{:__URL('__URL__/NsMemberShare/ADMIN_MODULE/MemberShare/index')}'">分享奖励设置</li>	
		<li onclick="location.href='{:__URL('__URL__/NsMemberShare/ADMIN_MODULE/MemberShare/shareConfig')}'">分享内容设置</li>
	</ul>
</nav>

<div class="space-10"></div>
<div class="set-style">
	<div class="set-item">
		<dl>
			<dt>分享送积分：</dt>
			<dd>
				<p><input id="share_point" type="number" value="{$reward_rule_info.share_point}" min="0"  onkeyup="value=value.replace(/[^\d+]/g,'')" class="input-common harf" ><em class="unit">分</em></p>
			</dd>
		</dl>
		<dl>
			<dt></dt>
			<dd>
				<p>
					<input id="share_open" type="checkbox" onchange="setMemberActionConfig();" class="checkbox" {if condition="$member_action_config['share_integral'] eq 1"}checked="checked"{/if}>
				</p>
				<p class="hint">是否启用分享送积分</p>
			</dd>
		</dl>
	
		<dl>
			<dt>分享送优惠券：</dt>
			<dd>
				<select class="row-no-radius select-common" id="share_coupon">
					<option value="">请选择优惠券种类</option>
					{foreach name="$coupon_list" item="v"}
						{if condition="$v['coupon_type_id'] == $reward_rule_info['share_coupon']"}
						<option value="{$v.coupon_type_id}" selected="selected">{$v.coupon_name}</option>
						{else/}
						<option value="{$v.coupon_type_id}">{$v.coupon_name}</option>
						{/if}
					{/foreach}
				</select>
			</dd>
		</dl>
		<dl>
		<dt></dt>
			<dd>
				<p>
					<input id="share_coupon_open" type="checkbox" onchange="setMemberActionConfig();" class="checkbox" {if condition="$member_action_config['share_coupon'] eq 1"}checked="checked"{/if}>
				</p>
				<p class="hint">是否启用分享送优惠券</p>
			</dd>
		</dl>
	</div>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="save();" style="margin:20px 0 20px 205px;">保存</button>
		</dd>
	</dl>
</div>
<script>
function setMemberActionConfig(){
	if($("#share_open").prop("checked")){
		var share = 1;
	}else{
		var share = 0;
	}

	if($("#share_coupon_open").prop("checked")){
		var share_coupon_open = 1;
	}else{
		var share_coupon_open = 0;
	}
	$.ajax({
		type : 'post',
		url : "{:__URL('__URL__/NsMemberShare/ADMIN_MODULE/MemberShare/setMemberActionConfig')}",
		data : {
			'share':share,
			'share_coupon':share_coupon_open
		},
		success : function(data){
			//alert(JSON.stringify(data));
		}
	})
}

function save(){
	var share_point = $("#share_point").val();
	var share_coupon = $("#share_coupon").val();
	if($("#share_open").prop("checked")){
		if(share_point == 0){
			showMessage("error","请设置分享积分");
			return;
		}
	}
	if($("#share_coupon_open").prop("checked")){
		if(share_coupon == ""){
			showMessage("error","请选择优惠券种类");
			return;
		}
	}
	$.ajax({
		type : 'post',
		url : "{:__URL('__URL__/NsMemberShare/ADMIN_MODULE/MemberShare/index')}",
		data : { "share_point" : share_point, 'share_coupon':share_coupon },
		success : function(data){
			if(data['code'] >=0){
				showMessage("success", "设置成功！", "{:__URL('__URL__/NsMemberShare/ADMIN_MODULE/MemberShare/index')}");
			}else{
				showMessage("error", "设置失败");
			}
		}
	})
}
</script>
{/block}